package com.ruoyi.machine.base.device.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.machine.base.device.domain.Device;
import com.ruoyi.machine.base.device.mapper.DeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备信息
 * 业务层处理
 * @author lsy
 */
@Service
public class DeviceServiceImpl implements IDeviceService{

    @Autowired
    private DeviceMapper deviceMapper;

    /**
     * 查询设备信息
     * @param device
     * @return
     */
    @Override
    public List<Device> selectDeviceList(Device device) {
        return deviceMapper.selectDeviceList(device);
    }

    /**
     * 通过id查询设备信息
     * @param machineId
     * @return
     */
    @Override
    public Device selectDeviceById(String machineId) {
        return deviceMapper.selectDeviceById(machineId);
    }

    /**
     * 添加设备
     * @param device
     * @return
     */
    @Override
    public int insertDevice(Device device) {
        if (StringUtils.isNotNull(deviceMapper.selectDeviceById(device.getMachineId()))) {
            //存在
            return 0;
        }
        //不存在
        return deviceMapper.insertDevice(device);
    }

    /**
     * 更新设备
     * @param device
     * @return
     */
    @Override
    public int updateDevice(Device device) {
        if (!StringUtils.isNotNull(deviceMapper.selectDeviceById(device.getMachineId()))) {
            //不存在
            return 0;
        }
        return deviceMapper.updateDevice(device);
    }

    /**
     * 删除设备
     * 仅修改删除标志
     * @param device
     * @return
     */
    @Override
    public int updateDeviceDeleteFlag(Device device) {
        return deviceMapper.updateDeviceDeleteFlag(device);
    }

    /**
     * 通过设备类型查询设备
     * @return
     */
    @Override
    public List<Device> selectAllMachineByType(String machineType) {
        return deviceMapper.selectAllMachineByType(machineType);
    }


}
